jQuery(function($) {
	var $slider = $('#home-slider > .flexslider');
	$slider.find('.flex-caption').each(function() {
		var $this = $(this);
		var configs = {
			left: $this.data('x'),
			top: $this.data('y'),
			speed: $this.data('speed'),
			delay: $this.data('start')
		};
		
		
		$this.data('positions', configs);
		
		$this.css({
			'left': configs.left,
			'top': configs.top,
			'animation-duration': configs.speed,
			'animation-delay': configs.delay
		});
	});
	
	$(window).on('resize', function() {
		var wW = $(window).width(),
			zoom = ( wW >= 1170 ) ? 1 : wW / 1349;
		$('.flex-caption.gfc').css('zoom', zoom);
	});
	$(window).trigger('resize');
	
	$("#home-slider").mouseover(function(){
		$(".flex-control-nav").css("display", "block"),
		$(".flex-direction-nav").css("display", "block");
	}).mouseout(function(){
		$(".flex-control-nav").css("display", "none"),
		$(".flex-direction-nav").css("display", "none");
	});
	
	$slider.imagesLoaded(function() {
		$slider.flexslider({
			animation: 'fade',
			easing: 'easeInQuad',
			slideshow: true,
			smoothHeight: false,
			directionNav: true,
			smoothHeight: true,
			nextText: '<i class="fa fa-angle-right"></i>',
			prevText: '<i class="fa fa-angle-left"></i>',
			start: function() {
				flex_fix_pos(1);
				$("#home-slider .flexslider").css('visibility','visible');
				$("#home-slider").addClass("fadeIn");
				$("#home-slider").removeClass("gf-ajaxloader");
			},
			before: function(slider) {
				// initial caption animation for next show
				$slider.find('.slides li .animation-done').each(function() {
					$(this).removeClass('animation-done');
					var animation = $(this).attr('data-animation');
					$(this).removeClass(animation);
				});
				
				flex_fix_pos(slider.animatingTo + 1);
			},
			after: function() {
				// run caption animation
				$slider.find('.flex-active-slide .animated').each(function() {
					var animation = $(this).attr('data-animation');
					$(this).addClass('animation-done').addClass(animation);
				});
			}
		});
	});

	$slider.ready(function(){
		$slider.find('.slides li:first .animation-done').each(function() {
			var animation = $(this).attr('data-animation');
			$(this).addClass('animation-done').addClass(animation);
		});
	});
	
	
	function flex_fix_pos(i) {
		$slider.find('.slides > li:eq(' + i + ') .gfc').each(function() {
			var $this = $(this),
				pos = $(this).data('positions');
			
		});
	}
});